package com.dhnsoft.代码随想录.哈希表;

import com.sun.xml.internal.ws.util.ASCIIUtility;

import java.util.Hashtable;

/**
 * ClassName: d01_242_有效的字母异位词
 * Package: com.dhnsoft.代码随想录.哈希表
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/13 9:18
 * @Version 1.0
 */
public class d01_242_有效的字母异位词 {
    public static void main(String[] args) {
        boolean anagram = isAnagram("rat", "cat");
        System.out.println(anagram);
    }


    public static boolean isAnagram(String s, String t) {
        char[] s1 = s.toCharArray();
        char[] s2 = t.toCharArray();
        if(s1.length!=s2.length){
            return false;
        }
        int[] hash = new int[26];
        for (int i=0;i<s1.length;i++){
            hash[s1[i]-97]++;
        }
        for (int j=0;j<s2.length;j++){
            hash[s2[j]-97]--;
        }
        for (int i=0;i<hash.length;i++){
            if(hash[i]!=0){
                return false;
            }
        }
        return true;

    }
}
